// pages/visitor/visitor.js
const request = require('../../utils/util')

Page({

  /**
   * 页面的初始数据
   */
  data: {
      description:'',
      address:'',
      owner:'',
      nickname:'',
      visitorList:[]
  },

  textareaAInput(e){
    this.setData({
      description:e.detail.value
    })
  },


  inputAddress(e){
    this.setData({
      address:e.detail.value
    })
  },

  inputNickName(e){
    this.setData({
      nickname:e.detail.value
    })
  },

  submit(){
    if(this.data.description == '' || this.data.address == "" || this.data.nickname == ""){
      wx.showToast({
        title: '输入有误',
        icon: 'none', // 提示框图标，none表示不显示图标
        duration: 2000 // 提示框持续时间，单位为毫秒，默认值是1500
      });
      return;
    }
    request.sendRequest("/visitor/addVisitor","POST",{
      description:this.data.description,
      address:this.data.address,
      owner:getApp().globalData.userInfo.id,
      nickname:this.data.nickname,
      type:1,
      status:1
    }).then((res) => {
      console.log(res)
    }).catch((err) => {
      console.log(err)
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.init()
  },

  yidao(event){
    var index = event.currentTarget.dataset.index;
    var placesToVisit = event.currentTarget.dataset.places;
    console.log(index)
    console.log(placesToVisit)
    request.sendRequest("/visitor/wx-changeStatus","GET",{
      placesToVisit:placesToVisit
    }).then((res)=>{
      console.log(res)
      this.init()
    }).catch((err)=>{
      console.log(err)
    })

  },

  init(){
    request.sendRequest("/visitor/wx-getVisitor","GET",{
      owner:getApp().globalData.userInfo.id
    }).then((res)=>{
      console.log(res)
      this.setData({
        visitorList:res.data
      })
    }).catch((err)=>{
      console.log(err)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})